package com.hfzy.ihk.web.freeswitchCall.support;

import com.hfzy.ihk.web.freeswitchCall.constant.RedisFields;
import com.hfzy.ihk.web.freeswitchCall.constant.RedisKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by YANFA on 2018/10/16.
 */
@Component
public class ColudCallUtils {


    Logger logger = LoggerFactory.getLogger(ColudCallUtils.class);
    @Autowired
    RedisTemplate redisTemplate;

    public  String  getCommitTo(String sessionId){

        Map<String,String> map= redisTemplate.opsForHash().entries(RedisKey.CALL_HISTORY_RPIX+sessionId);
        if(map==null)
            return null;
        String commitTo= map.get(RedisFields.CALL_HISTORY_COMMIT_TO);
        return commitTo;
    }

    public String getSessionIdByCallId(String callId){
        String sessionId = null;
        try {
             sessionId = String.valueOf(redisTemplate.opsForValue().get(RedisKey.CALL_IN + callId));

        }catch (Exception e){
            logger.error("呼入获取sessionId异常：{}",callId,e);
        }
        return sessionId;

    }
}
